package com.wuyou.simple;

import java.util.ArrayList;
import java.util.List;

/**
 * 1700. 无法吃午餐的学生数量
 */
public class CountStudents {

    public static void main(String[] args) {
        int[] students = {1,1,0,0}, sandwiches = {0,1,0,1};
        System.out.println(solution_1(students, sandwiches));
    }

    public static int solution_1(int[] students, int[] sandwiches) {

        int sandwIndex = 0;
        int stuIndex = 0;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < students.length; i++) {
            list.add(students[i]);
        }
        int length = list.size();
        while (true) {

            if (sandwiches[sandwIndex] == list.get(stuIndex)) {
                sandwIndex++;
                list.remove(stuIndex);
            }else {
                stuIndex++;
            }

            if (list.size() == 0) {
                break;
            }
            if (stuIndex == list.size()) {
                if (list.size() == length) {
                    break;
                }else {
                    stuIndex = 0;
                    length = list.size();
                }
            }
        }
        return list.size();
    }
}
